package com.ztools.pc.controller.coupon;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ztools.common.model.pc.coupon.CouponRecord;
import com.ztools.common.util.common.PageUtil;
import com.ztools.common.util.common.Result;
import com.ztools.pc.service.coupon.CouponRecordService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author: seeTools
 * @Date: 2023/5/11  15:56
 * @Version 1.0
 */
@RestController
@RequestMapping("/coupon/record")
public class CouponRecordController {

    @Resource
    private CouponRecordService couponRecordService;

    @RequestMapping("/list")
    public Result findList(@RequestBody PageUtil<CouponRecord> pageUtil) {
        Page<CouponRecord> list = couponRecordService.findList(pageUtil);
        return list != null ? Result.success("查询成功").data(list) : Result.error();
    }

    @RequestMapping("/delete")
    public Result delete(@RequestBody CouponRecord record) {
        boolean b = couponRecordService.delete(record);
        return b ? Result.success("删除成功") : Result.error();
    }

    @RequestMapping("/add")
    public Result add(@RequestBody CouponRecord record) {
        boolean b = couponRecordService.save(record);
        return b ? Result.success("添加成功") : Result.error();
    }

    @RequestMapping("/sendCouponByPhone")
    public Result sendCoupon(@RequestBody CouponRecord record) {
        boolean b = couponRecordService.sendCouponByPhone(record);
        return b ? Result.success("发送成功") : Result.error("不存在该会员");
    }

    @RequestMapping("/update")
    public Result update(@RequestBody CouponRecord record) {
        boolean b = couponRecordService.update(record);
        return b ? Result.success("修改成功") : Result.error();
    }

    @RequestMapping("/findByObject")
    public Result findByObject(@RequestBody CouponRecord record) {
        List<CouponRecord> list = couponRecordService.findByObject(record);
        return list != null ? Result.success("查询成功").data(list) : Result.error();
    }

    @RequestMapping("/export")
    public void excel(HttpServletResponse response, @RequestBody CouponRecord record) {
        couponRecordService.exportExcel(response, record);
    }
}
